<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<style type="text/css">
			div{
				width: 300px;
				height: 300px;
			}
		</style>
	</head>
	<body>
		<div id="div"></div>
		<script type="text/javascript">
			console.log(navigator.userAgent);
			var str=navigator.userAgent;
			var bro;
			var i=0;
			if(str.indexOf("OPR")!=-1){
				div.style.background="red";
				bro="Opera";
				console.log("这个浏览器为"+bro);
			}else if(str.indexOf("Chrome")!=-1){
				div.style.background="blue";
				bro="Chrome";
				console.log("这个浏览器为"+bro);
			}
			else if(str.indexOf("Firefox")!=-1){
				div.style.background="green";
				bro="Firefox";
				console.log("这个浏览器为"+bro);
			}
			
									
			if(bro=="Opera"){
				i=str.indexOf("OPR");
				var num=str.substr(i+4,4);
				console.log("版本号为"+num)
			}else if(bro=="Chrome"){
				i=str.indexOf("Chrome");
				console.log(i);
				var num=str.substr(i+bro.length+1,4);
				console.log("版本号为"+num)
			}else if(bro=="Firefox"){
				i=str.indexOf("Firefox");
				var num=str.substr(i+bro.length+1,4);
				console.log("版本号为"+num)
			}
		</script>
	</body>
</html>
